
# 9. 输出 9*9 乘法口诀表。
for x in range(1,10):
    for y in range(1,x+1):
        print(x," * ",y,' = ',x * y,end=" ")

    print()


# 10. 输入一行字符，分别统计出其中英文字母、空格、数字和其它字符的个数。
my_str = "h2中文"
char = 0
space = 0
number = 0
other = 0

for x in my_str:

    if x.isalpha():
        char += 1
    elif x.isdigit():
        number += 1
    elif x.isspace():
        space += 1
    else:
        other += 1

print("字符数量:",char)
print("数字数量:",number)
print("空格数量:",space)
print("其它字符数量:",other)

# 11. 求s=a+aa+aaa+aaaa+aa...a的值，其中a是一个数字。例如2+22+222+2222+22222(此时共有5个数相加)，几个数相加由键盘控制。
"""
2 = 2 + 0
22 = 20 + 2
222 = 200 + 22
2222 = 2000 + 222
22222 = 20000 + 2222

a = 2
temp = a * 10 ** n
sum += temp   == sum = temp + sum
"""

sum = 0
a = 2
temp = 0
n = int(input("请输入一个整数:"))
for i in range(n):
    temp = temp + a * 10 ** i
    sum += temp

print(sum)


# 12. 题目：打印出如下图案（菱形）:
x = 4
for n in range(1,x+1):
    star = '*' * (2*n - 1)
    space = " " * (x-n)
    print(space + star)

for n in range(1,x):
    star = "*" * (7 - 2*n)
    space = " " * n
    print(space + star)

# 第2种写法 ：center(width,fillchar)
x = 4
for n in range(1,x+1):
    star = '*' * (2*n - 1)
    print(star.center(7))